﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ADDDF.Infrastructure
{
    public static class Valid
    {
        public static void IfNotNullOrEmpty(string name, string value, int maxLength)
        {
            if (string.IsNullOrEmpty(value))
                throw new InvalidValueException(name, "cannot be null or empty string");

            if (value.Length > maxLength)
                throw new InvalidValueException(name, "cannot have more than " + maxLength.ToString() + " characters");
        }

        public static void IfNotNull(string name, object value)
        {
            if (value == null)
                throw new InvalidValueException(name, "cannot be null");
        }

        public static void IfInRange(string name, decimal min, decimal max, decimal value)
        {
            if (value < min || value > max)
                throw new InvalidValueException(name, "must be in range " + min + " - "  + max);
        }

        public static void IfAtLeast(string name, decimal min, decimal value)
        {
            if (value < min)
                throw new InvalidValueException(name, "must be at least " + min);
        }

        public static void IfDateOnly(string name, DateTime value)
        {
            if (value.Hour != 0 || value.Minute != 0 || value.Second != 0 || value.Millisecond != 0)
                throw new InvalidValueException(name, "cannot have Time component");
        }
    }
}
